<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>教师资料修改-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<script src="<%=basePath %>/js/picker.js"></script>
<script src="<%=basePath %>/js/select.js"></script>
<script src="<%=basePath %>/js/picker-city.js"></script>
</head>
<body ontouchstart id="tjjsqj">
	<div class="weui_tab tab-bottom">
		<div class="weui_tab_bd">
			<div class="weui-header bg-blue"> 
		  		<div class="weui-header-left"> <a onclick="back()" href="javascript:" class="icon icon-109 f-white">返回</a> </div>
		    	<h1 class="weui-header-title">教师信息变更</h1>
		    </div>
	        <div class="weui_cells" style="margin-top: 0;">
	            <div class="weui_cell">
	                <div class="weui_cell_hd" style="position: relative;margin-right: 15px;">
	                    <input type="hidden" id="id" name="id" value="${teacher.id }"/>
	                    <c:choose>
	                    	<c:when test="${teacher.headImgUrl == null }">
	                    		<img class="circle bg-blue-b" src="<%=basePath %>/images/default.jpg" style="width: 50px;display: block"/>
	                    	</c:when>
	                    	<c:otherwise>
	                    		<img class="circle bg-blue-b" src="${config.imgUrl }${teacher.headImgUrl}" style="width: 50px;display: block"/>
	                    	</c:otherwise>
	                    </c:choose>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input" name="name" id="name" value="${teacher.name }"></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">任教学科</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="subjectId" id="subjectId" value="${teacher.subjectText }" data-values="${teacher.subjectId }"/></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                	<label class="weui_label">年级</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr gradeSelect" name="grade" id="grade" value="${teacher.gradeText }" data-values="${teacher.grade }"/></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">登录密码</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="password" class="weui_input tr" name=password id="password" value="${teacher.password }" /></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                	<label class="weui_label">联系电话</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="mobile" id="mobile" value="${teacher.mobile }" placeholder="请输入联系电话"/></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">身份证号</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="idNo" id="idNo" value="${teacher.idNo }"  placeholder="请输入身份证号"/></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">出生日期</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="birthday" id="birthday" value="${teacher.birthday }" placeholder="请选择出生日期"/></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">性别</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="sex" id="sex" value="${teacher.sex }" placeholder="请选择性别" /></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">职称</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="techTitle" id="techTitle" value="${teacher.techTitle }" placeholder="请输入职称" /></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">籍贯</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="nativePlace" id="nativePlace" value="${teacher.nativePlace }" placeholder="请选择籍贯" /></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">民族</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="nation" id="nation" value="${teacher.nation }"  placeholder="请选择民族"/></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">政治面貌</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="geopolitical" id="geopolitical" value="${teacher.geopolitical }" placeholder="请选择政治面貌" /></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">入党团时间</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="partyDate" id="partyDate" value="${teacher.partyDate }" placeholder="请选择入党时间" /></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">户口所在地</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="homeAddr" id="homeAddr" value="${teacher.homeAddr }" placeholder="请选择户口所在地"/></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">居住地址</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="liveAddr" id="liveAddr" placeholder="请选择"/></p>
	                </div>
	            </div>
	            <div>
	            	<input type="text" class="weui_input tr" name="liveAddrDesc" id="liveAddrDesc" placeholder="请输入居住详细地址（具体到门牌）"/>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">户口性质</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="homeNature" id="homeNature" value="${teacher.homeNature }" placeholder="请选择户口性质"/></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">婚姻状况</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="isMarry" id="isMarry" value="${teacher.isMarry }" placeholder="请选择婚姻状况" /></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">毕业参加工作时间</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="workDate" id="workDate" value="${teacher.workDate }"  placeholder="请选择时间"/></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">大学专业</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="schoolMajor" id="schoolMajor" value="${teacher.schoolMajor }" placeholder="请输入大学专业"/></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">进我校时间</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="mySchoolDate" id="mySchoolDate" value="${teacher.mySchoolDate }" placeholder="请选择时间" /></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">是否正编教师</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="isOrganTeacher" id="isOrganTeacher" value="${teacher.isOrganTeacher }" placeholder="请选择"/></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">是否有普通话证</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="isChineseCard" id="isChineseCard" value="${teacher.isChineseCard }" placeholder="请选择" /></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">是否具备心理ABC证</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input tr" name="isPsychologyAbc" id="isPsychologyAbc" value="${teacher.isPsychologyAbc }" placeholder="请选择" /></p>
	                </div>
	            </div>
	            <div class="weui_cells_title">其他获得资格证书</div>
			  	<div class="weui_cell">
		          	<div class="weui_cell_bd weui_cell_primary">
		              	<textarea id="otherQualification" class="weui_textarea" name="otherQualification" rows="3" placeholder="请输入">${teacher.otherQualification }</textarea>
		          	</div>
		      	</div>
		      	<div class="weui_cells_title">曾获得荣誉</div>
			  	<div class="weui_cell">
		          	<div class="weui_cell_bd weui_cell_primary">
		              	<textarea class="weui_textarea" id="hadHonor" name="hadHonor" rows="3" placeholder="请输入">${teacher.hadHonor }</textarea>
		          	</div>
		      	</div>
	        </div>
	        
	        <div class="weui_btn_area">
		        <a href="javascript:" class="weui_btn bg-blue" id="teacherSubmit">确认提交</a>
		    </div>
		</div>
	</div>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>

<script type="text/javascript">
	$(function() {
		init();
		initLiveAddr("${teacher.liveAddr}");
		initGradeList();
		initSubjectList();
		$("#teacherSubmit").click(function() {
			teacherSubmit();
		});
	});
	function initLiveAddr(v) {
		if(!v) return;
		var array = v.split(",");
		$("#liveAddr").val(array[0]);
		$("#liveAddrDesc").val(array[1]);
	}
	function initGradeList() {
		$.ajax({
	 		url : basePath + "/gradeList",
	 		type : "post",
	 		dataType : "json",
	 		async : false,
	 		success : function(data) {
	 			var arr = [];
	 			for(var i in data){
	 		        if (data.hasOwnProperty(i)) {
	 		           arr.push({title: data[i], value: i})
	 		        };
	 		    }
	 			$("#grade").select({
	 		        title: "选择年级",
	 		        items: arr,
	 		        onChange: function(d) {
	 		        	this.dialog.remove();
	 		        }
	 		    });
	 		}, error:function(){
	 			alert("删除照片异常");
      		}
        });
	}
	function initSubjectList() {
		$.ajax({
	 		url : basePath + "/subjectList",
	 		type : "post",
	 		dataType : "json",
	 		async : false,
	 		success : function(data) {
	 			var arr = [];
	 			for(var i in data){
	 		        if (data.hasOwnProperty(i)) {
	 		           arr.push({title: data[i], value: i})
	 		        };
	 		    }
	 			$("#subjectId").select({
	 		        title: "选择学科",
	 		        items: arr,
	 		        onChange: function(d) {
	 		        	this.dialog.remove();
	 		        }
	 		    });
	 		}, error:function(){
	 			
      		}
        });
	}
	function teacherSubmit() {
		var name = $("#name").val();
		var subjectId = $("#subjectId").attr("data-values");
		var grade = $("#grade").attr("data-values");
		var mobile = $("#mobile").val();
		var idNo = $("#idNo").val();
		var password = $("#password").val();
		if(!checkName(name)) {
			$.toast("姓名格式不正确", "forbidden");
			return;
		}
		if(password.trim().length == 0) {
			$.toast("密码不能为空", "forbidden");
			return;
		}
		var sex = $("#sex").val();
	    var birthday = $("#birthday").val();   
	    var education = $("#education").val();
	    var techTitle = $("#techTitle").val();
	    var nativePlace = $("#nativePlace").val();
	    var nation = $("#nation").val();
	    var geopolitical = $("#geopolitical").val();
	    var partyDate = $("#partyDate").val();
	    var homeAddr = $("#homeAddr").val();
	    var liveAddr = $("#liveAddr").val();
	    var liveAddrDesc = $("#liveAddrDesc").val();
	    var homeNature = $("#homeNature").val();
	    var isMarry = $("#isMarry").val();
	    var workDate = $("#workDate").val();
	    var schoolMajor = $("#schoolMajor").val();
	    var mySchoolDate = $("#mySchoolDate").val();
	    var isOrganTeacher = $("#isOrganTeacher").val();
	    var isChineseCard = $("#isChineseCard").val();
	    var isPsychologyAbc = $("#isPsychologyAbc").val();
	    var otherQualification = $("#otherQualification").val();
	    var hadHonor = $("#hadHonor").val();
	    if(liveAddr) {
	    	if(!liveAddrDesc.trim()) {
	    		$.toast("请输入居住详细地址", "forbidden");
				return;
	    	}
	    	liveAddr += "," + liveAddrDesc.trim();
	    }
		$.ajax({
	 		url : basePath + "/ls/teacher/manage/info/update",
	 		type : "post",
	 		dataType : "json",
	 		data: {
	 			id: $("#id").val(),
	 			subjectId: subjectId,
	 			grade: grade,
	 			mobile: mobile,
	 			idNo: idNo,
	 			password: password,
	 			sex: sex,
	 	    	birthday: birthday,
		 	    education: education,
		 	    techTitle: techTitle,
		 	    nativePlace: nativePlace,
		 	    nation: nation,
		 	    geopolitical: geopolitical,
		 	    partyDate: partyDate,
		 	    homeAddr: homeAddr,
		 	    liveAddr: liveAddr,
		 	    homeNature: homeNature,
		 	    isMarry: isMarry,
		 	    workDate: workDate,
		 	    schoolMajor: schoolMajor,
		 	    mySchoolDate: mySchoolDate,
		 	    isOrganTeacher: isOrganTeacher,
		 	    isChineseCard: isChineseCard,
		 	    isPsychologyAbc: isPsychologyAbc,
		 	    otherQualification: otherQualification,
		 	    hadHonor: hadHonor
	 		},
	 		async : false,
	 		success : function(data) {
	 			if(data.code == '000') {
	 				$.toast("修改成功");
	 				return;
	 			}
	 			$.toast(data.msg, "cancel");
	 		}, error:function(){
	 			alert("修改异常");
      		}
        });
	}
	function init() {
		$("#birthday").datetimePicker({title:"选择日期",m:1});
		$("#partyDate").datetimePicker({title:"选择日期",m:1});
		$("#workDate").datetimePicker({title:"选择日期",m:1});
		$("#mySchoolDate").datetimePicker({title:"选择日期",m:1});
		$("#sex").picker({
	        title: "请选择性别",
	        autoClose:true,
	        cols: [{textAlign: 'center',
	                 values: ['男', '女']
	               }]
        });
		$("#isOrganTeacher").picker({
	        title: "是否正编教师",
	        autoClose:true,
	        cols: [{textAlign: 'center',
	                 values: ['是', '否']
	               }]
        });
		$("#isChineseCard").picker({
	        title: "是否有普通话证",
	        autoClose:true,
	        cols: [{textAlign: 'center',
	                 values: ['是', '否']
	               }]
        });
		$("#isPsychologyAbc").picker({
	        title: "是否具备心理ABC证",
	        autoClose:true,
	        cols: [{textAlign: 'center',
	                 values: ['是', '否']
	               }]
        });
		$("#isMarry").picker({
	        title: "婚姻状况",
	        autoClose:true,
	        cols: [{textAlign: 'center',
	                 values: ['已婚', '未婚', "离婚"]
	               }]
        });
		$("#education").picker({
	        title: "请选择学历",
	        autoClose:true,
	        cols: [{textAlign: 'center',
	                 values: ['中专', '大专', "本科", "硕士研究生", "博士"]
	               }]
        });
		$("#geopolitical").picker({
	        title: "请选择政治面貌",
	        autoClose:true,
	        cols: [{textAlign: 'center',
	                 values: ['群众', '共产党员', "共青团员", "其它"]
	               }]
        });
		$("#nation").picker({
	        title: "请选择民族",
	        autoClose:true,
	        cols: [{textAlign: 'center',
	                 values: ["汉族", "蒙古族",  "回族", "藏族", "维吾尔族", "苗族",  "彝族", "壮族", "布依族", "朝鲜族",
	                          "满族", "侗族", "瑶族", "白族", "土家族", "哈尼族", "哈萨克族", "傣族", "黎族", "傈僳族",
	                          "佤族", "畲族", "高山族", "拉祜族", "水族", "东乡族", "纳西族", "景颇族", "柯尔克孜族",
	                          "土族", "达斡尔族", "仫佬族", "羌族", "布朗族", "撒拉族", "毛南族", "仡佬族", "锡伯族",
	                          "阿昌族", "普米族", "塔吉克族", "怒族", "乌孜别克族", "俄罗斯族", "鄂温克族", "德昂族",
	                          "保安族", "裕固族", "京族", "塔塔尔族", "独龙族", "鄂伦春族", "赫哲族", "门巴族", "珞巴族",
	                          "基诺族", "亻革家人", "穿青人"]
	               }]
        });
		$("#nativePlace").cityPicker({
	        title: "请选择省市区"
	    });
		$("#liveAddr").cityPicker({
	        title: "请选择省市区"
	    });
		$("#homeAddr").cityPicker({
	        title: "请选择省市区"
	    });
		$("#homeNature").picker({
			 title: "请选择户口性质",
		     autoClose:true,
		     cols: [{textAlign: 'center',
                values: ["农业","非农业"]
              }]
		});
	}
</script>
</body>
</html>